package com.fog.student.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fog.student.common.Base;
import com.fog.student.dto.CourseDto;
import com.fog.student.entity.Course;
import com.fog.student.entity.Student;
import com.fog.student.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.security.PublicKey;

@RestController
@Slf4j
@RequestMapping("/course")
public class CourseController {
    @Resource
    private CourseService courseService;

    @GetMapping("/page")
    public Base page(Integer page, Integer pageSize, String name){
        Page<CourseDto> pageInfo = courseService.pageSearch(page,pageSize,name);
        return Base.success(pageInfo);
    }
    @PostMapping("/status/{status}")
    public Base changeStatus(@PathVariable int status,String ids){
        String[] idList = ids.split(",");
        for (String id : idList) {
            Course course = new Course();
            course.setId(Integer.parseInt(id));
            course.setStatus(status);
            courseService.updateById(course);
        }

        return Base.success("更新状态成功");
    }
    @PostMapping
    public Base addCourseDto(@RequestBody CourseDto courseDto){

        courseService.addCourse(courseDto);
        return Base.success("添加成功");
    }
    @DeleteMapping
    public Base deleteCourse(String ids){
        courseService.deleteCourse(ids);
        return Base.success("删除成功");
    }
}
